<?php

Class Controller_Comment Extends Controller_Base {
	function index(){
		echo "comment";
	}
	
	function block(){
		if(!User::checkAccess('admin'))die('Ошибка доступа!');
		$id = isset($_POST['id'])?$_POST['id']:-1;
		if($id!=-1){
			Comment::set(array('state'=>"-1"),$id);
		}
	}
	
	function new_(){
		if(User::getState()!=1&&!User::checkAccess('admin'))die('Ошибка доступа!');
		$p = $_POST;
		if(isset($p['form'])&&isset($p['id'])){
			$comment 		= Comment::get($p['id']);
			if(isset($comment[0]['state'])&&$comment[0]['state']!=-1){
				$res['html'] 	= Comment::getViewData(-1,$p['id']);
				$res['title'] 	= "Создание комментария";
				echo json_encode($res);
			}else{
				header("HTTP/1.0 404 Not Found");
				die('Error 10301.12.3.1');
			}
		}else{
			$v = Comment::validate();
			if($v['state']==1){
				$res = Comment::create($p);
				$res['state'] = 1;
				$res['msg']   = "Комментарий успешно добавлен.";
				echo json_encode($res);
			}else{
				echo json_encode($v);
			}
		}
	}
}

?>